<template>
  <div class="Data">
    <el-table :data="tableData">
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="phone" label="手机"></el-table-column>
      <el-table-column prop="company" label="公司名称" show-overflow-tooltip></el-table-column>
      <el-table-column prop="email" label="邮箱" show-overflow-tooltip></el-table-column>
      <el-table-column prop="channel" label="渠道来源" show-overflow-tooltip></el-table-column>
      <el-table-column prop="business" label="咨询业务" show-overflow-tooltip></el-table-column>
      <el-table-column prop="createTime" :formatter="formatter" label="创建时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="caozuo" label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSie"
        :page-sizes="[10, 20, 30, 40,50]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="count"
      ></el-pagination>
    </div>
    <MyDialog title="删除" ref="deleteTeam" lastText="删除" :colorType="true" @saveHandle="deleteTeam">
      <p class="tips">确定删除吗？</p>
      <p>删除后此人员前台将不再显示</p>
    </MyDialog>
  </div>
</template>
<script>
import MyDialog from "../components/dialog";
export default {
  name: "Data",
  components: {
    MyDialog
  },
  data() {
    return {
      pageSie: 10,
      count: 1000,
      currentPage: 1,
      tableData: [],
      did: ""
    };
  },
  methods: {
    handleDelete(row) {
      this.did = row.did;
      this.$refs.deleteTeam.show();
    },
    //确定删除
    deleteTeam() {
      this.$post("/order/delete", { did: this.did }).then(res => {
        if (res.code == 200) {
          this.$message.success("删除成功");
          this.$refs.deleteTeam.hide();
          this.getList();
        }
      });
    },
    //时间搓处理
    formatter(row, column) {
      let pro = column.property;
      let dates = row[pro];
      if (dates == "0") {
        return "-";
      } else {
        var date = new Date(dates);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? "0" + m : m;
        var d = date.getDate();
        d = d < 10 ? "0" + d : d;
        let hour = date.getHours();
        if (hour < 10) {
          hour = "0" + hour;
        }
        let minute = date.getMinutes();
        if (minute < 10) {
          minute = "0" + minute;
        }
        let second = date.getSeconds();
        if (second < 10) {
          second = "0" + second;
        }
        return (
          y + "-" + m + "-" + d + "\xa0 " + hour + ":" + minute + ":" + second
        );
      }
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSie = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
    },
    getList() {
      this.$post("/order/list", {
        page: this.currentPage,
        pageSie: this.pageSie
      }).then(res => {
        if (res.code == 200) {
          const { data } = res;
          this.count = data.count;
          this.tableData = data.orders;
        }
      });
    }
  },
  created() {
    this.getList();
  },
  mounted() {
    this.$parent.setPannelName([
      {
        name: "数据搜集",
        path: "/Data"
      }
    ]);
  }
};
</script>
<style lang="less" scoped>
.page {
  text-align: center;
  margin-top: 20px;
}
.tips {
  font-weight: normal;
  font-size: 32px;
  margin-bottom: 50px;
}
</style>